package com.miplus.ccrm.core.controller;

import com.miplus.ccrm.common.R;
import com.miplus.ccrm.core.controller.vo.ImgeReqVo;
import com.miplus.ccrm.core.controller.vo.ImgeResVo;
import com.miplus.ccrm.core.service.cust.ConCustomerService;
import com.miplus.ccrm.core.service.sto.ImgService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 影像平台接口
 */
@Slf4j
@CrossOrigin(origins = "*", maxAge = 3600)
@RestController
@RequestMapping("/sto")
public class ImgController {


//    @Value("${hrbank.image.pla.tranCode}")
    private String tranCode;
//    @Value("${hrbank.image.pla.sysId}")
    private String sysId;
//    @Value("${hrbank.image.pla.sysKey}")
    private String sysKey;
//    @Value("${hrbank.image.pla.uipIp}")
    private String uipIp;
//    @Value("${hrbank.image.pla.uipPort}")
    private String uipPort;

    @Resource
    ConCustomerService conCustomerService;

    @Resource
    ImgService imgService;

    /**
     * 影响获取
     * @param reqVo
     * @return
     */
    @PostMapping("/img2002")
    public R<ImgeResVo> img2002(@RequestBody @Validated ImgeReqVo reqVo){
        //
        log.info("reqVo.getCustomernumber():"+reqVo.getCustomernumber());

        String openacctcertno = conCustomerService.getById(reqVo.getCustomernumber()).getOpenacctcertno();
        log.info("identity:{}",openacctcertno);
        ImgeResVo imgeResVo = new ImgeResVo();

/**
        Map<String,Object> saveMap = new HashMap<String,Object>();
        saveMap.put("tranCode", tranCode);
        saveMap.put("sysId", sysId);//系统来源系统简称
        saveMap.put("sysKey", sysKey);//系统密钥
        saveMap.put("uipIp", uipIp);//访问ip
        saveMap.put("uipPort", uipPort);//访问端口
//        saveMap.put("idNo", "310120198408292298");//证件号
        saveMap.put("idNo", openacctcertno);
        ImageGain2002Return imageGain2002Return = ImageGain2002Service.transferToReturn(saveMap);
//        List<Map<String, String>> fileInfo = null;
        JSONArray sss=new JSONArray();
        List<Map<String, String>> fileInfo = imageGain2002Return.getFileInfo();
//        String string = fileInfo.get(0).toString();
//        System.out.println(jsonObject.toString());
//        sss.add(jsonObject);
//        String ss="http://10.132.81.175:9081/httpfiletrans/HttpFileTrans?method=download&BufferSize=65536&FlushSize=65536&IsCreateDir=TRUE&FilePath=/UIP/CCR/2021/9/22/CCRXHOP00000002021092211190774746562/d9408de8697348dda36a04251ea95310.pdf&NasFlag=1";
//        System.out.println(ss);

        fileInfo.forEach(x->{
            System.out.println(x);
            JSONObject jsonObject=new JSONObject();
            jsonObject.put("fileUrl",x.get("fileUrl"));
            jsonObject.put("billType",x.get("billType"));
            jsonObject.put("fileName",x.get("fileName"));
            jsonObject.put("fileType",x.get("fileType"));
            jsonObject.put("fileId",x.get("fileId"));
//            jsonObject.put("remark",x.get("remark"));
//            jsonObject.putAll(fileInfo.get(0));
            sss.add(jsonObject);
//            System.out.println("--------------------------------");
//            System.out.println(x.get("fileUrl"));
//            x.forEach((key,v)->{
//                jsonObject.put(key,v);
//                System.out.println("key:"+key+"v:"+v);
//                if(v!=null){
//                    jsonObject.put(key,v);
//                }
//            });
        });**/
//        imgeResVo.setFileInfo(sss);
        return R.Success(imgeResVo);
    }


    /**
     * 影像平台录音调听
     * @param skyid  ndcs:callid ,  dcs:actionId
     * @param ide 标识 1:ndcs 2:dcs
     * @param response
     * @return
     */
    @GetMapping("/play")
    public R imgPlay(String skyid,String ide, HttpServletResponse response){

        imgService.OnPlayFileImg(skyid,ide,response);
        return R.Success();
    }
}
